package com.endurance.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.stereotype.Component;

@Component
public class ServiceAdvice {

    public void beforeAdvice() {
        System.out.println("前置通知...");
    }

    public void afaterAdvice() {
        System.out.println("后置通知...");
    }

    public void finallyAdvice() {
        System.out.println("最终通知...");
    }

    public void afterThrowingAdvice() {
        System.out.println("异常通知...");
    }

    public void aroundAdvice(ProceedingJoinPoint proceedingJoinPoint) {
        try {
            System.out.println("环绕通知-前置通知...");
            //环绕通知配置 目标方法的执行位置
            proceedingJoinPoint.proceed();
            System.out.println("环绕通知-后置通知...");
        } catch (Throwable e) {
            System.out.println("环绕通知-异常通知...");
            throw new RuntimeException(e);
        } finally {
            System.out.println("环绕通知-最终通知...");
        }
    }

}
